# Everything has a URI

# So instead of defining routes, we define URI's

# Since we have several separate interface we also need to separate them
# in code. Originally we do that using mixins we include at runtime into
# the request. Is there a better way?

# In other words, responses are polymorphic. Do we then factor out a response
# object?

Server.dispatch do
  if params[:q]
    API.handler(params[:q], self) # choose the class by the query type
  elsif @headers[ACCEPT] =~ WAP_ACCEPT_REGEXP
    WapHandler.new(self)
  elsif @path =~ /^\/basic(\/.+)?/
    BasicHandler.new(self)
  else
    WebHandler.new(self)
  end
end

# where

WapHandler < ServerSide::Handler
  CATCH_ALL = /(.*)/.freeze
  route :login, :params => {:m => :login} do
    render_wap :login
  end

  default_route do
    redirect :login unless @session
    
    node = Node/path
    raise "Invalid node" if node.nil?
    validate_permission(node, :read)
    case node.kind
    when Node::Point
      render_wap :point
    when Node::Group
      render_wap :group
    else
      raise "Invalid node kind"
    end
  end
  
  on_error {render_wap :error} # the error object is stored in @error
end

# Here's the interesting part

class WebHandler < ServerSide::Handler
  route :pane, :params => {:p = :pane} do
    route 
  end
end

